﻿namespace Wisdom.Core
{
    /// <summary>
    /// 描述：配置器基类
    /// </summary>
    /// <typeparam name="TContainer">对象容器类型.</typeparam>
    public abstract class Configurator<TContainer> : IConfigurator<TContainer>
    {
        #region Private Fields
        private readonly IConfigurator<TContainer> context;
        #endregion

        #region Ctor
        /// <summary>
        /// 构造函数：实始化 <c>Configurator{TContainer}</c> 类实例.
        /// </summary>
        /// <param name="context">类 <see cref="IConfigurator{TContainer}"/> 实例.</param>
        /// 参数 <paramref name="context"/>指定配置上下文，并配置前上一步来配置当前步
        /// </remarks>
        protected Configurator(IConfigurator<TContainer> context)
        {
            this.context = context;
        }
        #endregion

        #region Public Properties
        /// <summary>
        /// 获得配置上下文实例
        /// </summary>
        public IConfigurator<TContainer> Context
        {
            get { return this.context; }
        }
        #endregion

        #region Protected Methods
        /// <summary>
        /// Configures the container.
        /// </summary>
        /// <param name="container">The object container to be configured.</param>
        /// <returns>The configured container.</returns>
        protected abstract TContainer DoConfigure(TContainer container);
        #endregion

        #region IConfigurator<TContainer> Members
        /// <summary>
        /// 配置容器
        /// </summary>
        /// <returns>配置容器.</returns>
        public TContainer Configure()
        {
            var container = this.context.Configure();
            return DoConfigure(container);
        }

        #endregion
    }
}